﻿using System;
using System.Xml;
using System.Collections.Generic;
using SdmxMl.Common;
using SdmxMl.Structure;
using System.Data;
using SdmxMl.Multiplexor;

namespace SdmxMl.Manager
{
    public interface IRegistry
    {
        #region Methods for accessing TinyRegistry Service

        bool IsNewSmsRegistry { get; }

        /// <summary>
        /// Ownership only for new SMS registry
        /// </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="ownerId">update owner string id</param>
        void UpdateOwner(string artType, string fullId, string ownerId);

        /// <summary>
        /// Obtain list of ownership group where user is associated
        /// </summary>
        /// <returns>the list of associated owner group</returns>
        List<string> UserOwnerList();
 

        /// <summary> Get last version of specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <returns>last version as string</returns>
        string GetLastVersion(string arType, string fullIdent);

        /// <summary> Get SDMX document of specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <returns>SDMX document matching request</returns>
        XmlDocument GetArtefact(string arType, string fullIdent);

        /// <summary> Check presence of specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <returns>True if exist, false otherwise</returns>
        bool ExistArtefact(string arType, string fullIdent);

        /// <summary> Remove from registry the specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        void DeleteArtefact(string arType, string fullIdent);

        /// <summary> Set diffusion status of the specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="diffusionCd">diffusion code to set</param>
        void SetDisseminationStatus(string artType, string fullId, string diffusionCd);

        /// <summary> register the specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="xDoc">the maintenable artefact sdmx document</param>
        void SubmitArtefact(string arType, string fullIdent, XmlDocument xDoc);

        /// <summary> Reserve (lock) the specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        void CheckOut(string arType, string fullIdent);


        /// <summary> Liberate (unlock) the specified maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        void UndoCheckOut(string arType, string fullIdent);

        /// <summary> Update text part of the specified finalized maintenable artefact </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="xDoc">the maintenable artefact sdmx document</param>
        void UpdateFinalizedArtefact(string arType, string fullIdent, XmlDocument xDoc);

        /// <summary>Retrieves list of artefact for specified type</summary>
        /// <param name="arType">Artefact type</param>
        /// <returns>A dataset holding the information table</returns>
        DataSet DirInfo(string arType);

        /// <summary>Retrieves information list of artefact for specified type </summary>
        /// <param name="arType">Artefact type</param>
        /// <param name="agencyId">Agency (group ID)</param>
        /// <returns>A dataset holding the information table</returns>
        DataSet DirInfo(string arType, string agencyId);

        /// <summary> Is specified maintenable artefact updated since cache date </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="dtCache">date of cached version</param>
        /// <returns>True if registry artefact content updated since cache date </returns>
        bool IsArtefactUpdated(string arType, string fullIdent, DateTime dtCache);

        /// <summary> Check if maintenable artefact has backup in registry </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <returns>True if registry contains backup for specified artefact</returns>
        bool HasBackup(string arType, string fullIdent);

        /// <summary> register the specified maintenable artefact, make a backup of previous registry version if any </summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="xDoc">the maintenable artefact sdmx document</param>
        void SubmitArtefactBackup(string arType, string fullIdent, XmlDocument xDoc);

        /// <summary>Get list of backup of specified maintenable artefact</summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <returns>A dataset holding the information table</returns>
        DataSet GetBackupList(string arType, string fullIdent);

        /// <summary>Get SDMX document of specified backup of maintenable artefact</summary>
        /// <param name="arType">Type of artefact</param>
        /// <param name="fullIdent">AgencyId + Id + version</param>
        /// <param name="backupNumber">backup number for this artefact</param>
        /// <returns>SDMX document of artefact content matching the backup number</returns>
        XmlDocument GetArtefactBackup(string arType, string fullIdent, string backupNumber);

        /// <summary>Is connected user in administrative role</summary>
        /// <returns>True if administrator, false otherwise</returns>
        bool UserIsAdmin { get; }

        /// <summary>Get Mail of specified user</summary>
        /// <param name="userId">the user ident. </param>
        /// <returns>eMail string or empty string if not found</returns>
        string GetMailOfUser(string userId);

        string ConnectedInfo { get; }

        #endregion


        MultiplexorState State { get; }
        string ErrorStateMessage { get; }
        bool RunningOK { get; }
        bool ConfigMultiplexed { get; }

        DataTable TableGroups { get; }
        DataTable TableRegistry { get; }

        string UserId { get; set; }

        string DirInfoRegistryAlias { get; }
        string DirInfoAgencyFilter { get; }

        CodeListType ClGroup { get; }

        ProxyService DirInfoProxy { get; }
        void SetDirInfoProxy(string url);
        ProxyService GetProxyForGroup(string groupInfo);

        void DistributeOrgScheme();

        Ch.Admin.Bfs.Sms.Sdmx.Registry.Rights.ISecuredArtefactRegistry GetNewRegistry();
        Ch.Admin.Bfs.Sms.Sdmx.Registry.Proxies.WcfAdministrationProxy GetAdminRegistry();
        Ch.Admin.Bfs.Sms.Sdmx.Registry.Proxies.WcfNotificationsProxy GetNotificationRegistry(); 

    }
}
